package entity_controllers.fieldcontrollers;

import boundary.UI;
import ie.FieldBoard;
import ie.PlayerBoard;
import ie.Shaker;
import controllers.FieldController;
import core.subcontrollers.PlayerController;
import dto.Field;
import dto.Player;
import entity.fields.Tax;

public class TaxController extends FieldController {
	
	@Override
	public void execute(Player player, Field field, FieldBoard arg2,
			PlayerBoard arg3, Shaker arg4) {
		Tax taxField = ((Tax)arg2.getField(player.getFieldIndex()));
		int taxValue = taxField.getTaxValue();
		
		if (taxField.isIncomeTax()){
			//Pay a fixed amount decision
			if (UI.get().getBoolean("Vælg hvad du vil betale", ""+taxField.getTaxValue(), "10%"))
				PlayerController.payAmount(player, null, taxValue);
			
			//Pay 10% decision
			else {
				int tenPercentageOfAsset = (int) (0.1 * player.getAccount().getTotalAssets());
				while(tenPercentageOfAsset % 50 != 0)
					tenPercentageOfAsset++;
				
				PlayerController.payAmount(player, null, tenPercentageOfAsset);
			}
		}
		else
			PlayerController.payAmount(player, null, taxValue);
		
		UI.get().showPlayer(player);
	}
}
